import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'font-awesome/css/font-awesome.css'
import axios from 'axios'
import qs from 'qs'
import {
	getCurDate,
	setSessionStorage,
	getSessionStorage,
	removeSessionStorage,
	setLocalStorage,
	getLocalStorage,
	removeLocalStorage
} from './common.js'

Vue.config.productionTip = false

//设置axios的url基础部分
axios.defaults.baseURL='http://localhost:8080/elm/'
//设置axios的简写方式  this.$axios 
Vue.prototype.$axios = axios;
//设置qs的简写方式
Vue.prototype.$qs = qs;
//设置common函数中的简写方式
Vue.prototype.$getCurDate =  getCurDate;
Vue.prototype.$setSessionStorage = setSessionStorage;
Vue.prototype.$getSessionStorage =getSessionStorage;
Vue.prototype.$removeSessionStorage =removeSessionStorage;
Vue.prototype.$setLocalStorage =setLocalStorage;
Vue.prototype.$getLocalStorage =getLocalStorage;
Vue.prototype.$removeLocalStorage=removeLocalStorage;

//导航守卫
router.beforeEach(function(to,from,next){
	var user = sessionStorage.getItem('user');
	if(!(to.path=='/'||
		to.path=='/index'||
		to.path=='/businessList'||
		to.path=='/businessInfo'||
		to.path=='/login'||
		to.path=='/register')){
			//如果不是以上这些页面,就要判断用户是否存在
			//如果sessionStorage中不存在该用户,就让它跳转到登陆页面
		if(user==null){
			router.push('/login');
			location.reload();
		}
	}
	next();
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
